#!/bin/sh  
  
# 记录日志  
echo "$(date) Action: $ACTION Product: $PRODUCT Interface: $INTERFACE" >> /tmp/hotplug.log  
  
# 定义要添加的命令  
CMD_TO_ADD="sh /usr/sbin/4g-init"  
  
# 检查是否是WWAN网卡并且动作是添加  
if [ "${PRODUCT}" = "19d2/199/100" ] && [ "${ACTION}" = "add" ]; then  
    # 首先执行命令  
    $CMD_TO_ADD &
	cmd_process_id=$! 
	uci set network.4g=interface
        uci set network.4g.proto='dhcp'
        uci set network.4g.ifname='eth1'
        uci commit network
        uci set firewall.@zone[1].network='wan wan6 4g'
        uci commit firewall

  
    # 检查命令是否已经在/etc/rc.local中存在，如果不存在则添加  
    if ! grep -qFx -- "$CMD_TO_ADD" /etc/rc.local; then  
        # 使用sed在exit 0之前插入命令  
        sed -i '/exit 0/i \\'"$CMD_TO_ADD" /etc/rc.local  
    fi  
fi  
#wait the process,then start network
wait $cmd_process_id
/sbin/ifdown eth1 && /sbin/ifup eth1

# 检查是否是WWAN网卡并且动作是删除 
if [ "${PRODUCT}" = "19d2/199/100" ] && [ "${ACTION}" = "remove" ]; then  
    # 使用sed删除匹配的行，同时考虑可能的空白字符  
 escaped_cmd=$(echo "$CMD_TO_ADD" | sed 's/\//\\\//g')
sed -i "/^${escaped_cmd}$/d" /etc/rc.local
	uci delete network.4g                                
        uci commit network              
        uci set firewall.@zone[1].network='wan wan6'
        uci commit firewall     
        /etc/init.d/network restart
fi 
